Skip to content

Sync Array's & TypedArray's "includes" with spec #931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 31, 2019
Merged

Sync Array's & TypedArray's "includes" with spec #931

merged 6 commits into from
Oct 31, 2019

Conversation

MaxGraey
Copy link
Member

@MaxGraey MaxGraey commented Oct 29, 2019

With Array.p.include we forgot one piece of puzzle. include use Object.is instead == for element's comparison and in contrast with indexOf. So we couldn't use return arr.indexOf() >= 0 for this.

Before:

([NaN] as f64[]).includes(NaN) // -> false (which is wrong)
([NaN] as f64[]).indexOf(NaN) // -> -1

with PR:

([NaN] as f64[]).includes(NaN) // -> true
([NaN] as f64[]).indexOf(NaN) // -> -1

@MaxGraey MaxGraey requested a review from dcodeIO October 29, 2019 00:21
@MaxGraey MaxGraey changed the title Sync Array's & TypedArray's include with spec Sync Array's & TypedArray's "includes" with spec Oct 29, 2019
@MaxGraey MaxGraey requested a review from dcodeIO October 30, 2019 00:19
Comment on lines +3505 to +3509
(func $~lib/number/isNaN<f64> (; 62 ;) (type $FUNCSIG$id) (param $0 f64) (result i32)
local.get $0
local.get $0
f64.ne
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcodeIO We definitely need tune inlining limits more better than binaryen's defaults.

Copy link
Member

@dcodeIO dcodeIO Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's interesting. From looking over the inlining limits, this one seems as if it is smaller than flexibleInlineMaxSize = 20 and should be considered lightweight (maybe it isn't?), so it should inline if optimizeLevel >= 3 and shrinkLevel == 0. (see)

Copy link
Member Author

@MaxGraey MaxGraey Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in -O3 it will be inlined but I guess even with shrinkLevel == 1 this should be possible. Only for shrinkLevel == 2 and 3 this unnecessary. -O3z used by default so it pretty important provide nearly identical speed with -O3 with just slightly smaller size

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw fan fact:
-O3 example with four isNaN: https://webassembly.studio/?f=tsbtqbkt2ks
has size: 123 bytes and with inlines

Same example but with -O3z: https://webassembly.studio/?f=4jfqpshboq9
142 bytes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess sometimes, when code is inlined, even if it doesn't meet the inlining criteria introduced to avoid growing, it can be optimized much better further down the road than if it remained its own small function. The challenge here seems to be to detect that condition, which would have to estimate how much inlining a function that isn't considered worth inlining at first actually benefits from other passes after inlining. Quite a hard problem, that doesn't seem to be solvable by just tweaking the inlining options because this would then also inline stuff that doesn't actually benefit from other passes. As such, I think Binaryen is doing what it reasonably can do without either recompiling multiple times to observe the difference or go completely crazy trying to build an estimator.

Copy link
Member

@dcodeIO dcodeIO Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe one assumption we could apply in Os is to ignore pushes to the stack involving function arguments, like the local.gets in this specific example, expecting that these will usually blend in fine into the call site? I'm guessing, but that's somewhat testable. We'd then have a conservativeSize and an eagerSize when checking worthInlining. Maybe. Perhaps.

@MaxGraey MaxGraey requested a review from dcodeIO October 31, 2019 15:53
@dcodeIO dcodeIO merged commit 3f34964 into AssemblyScript:master Oct 31, 2019
@dcodeIO
Copy link
Member

dcodeIO commented Oct 31, 2019

Thanks! :)

@MaxGraey MaxGraey deleted the fix-array-includes branch October 31, 2019 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants